package com.xie.sort;

import java.util.Scanner;

public class test1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());

        String[] vStr = {"", "", "", "", ""};
        for (int i = 0; i < n; i++) {
            String str = sc.nextLine();
            vStr[i] = str;
        }

        int valueSum = 0;
        for (int i = 0; i < vStr.length; i++) {
            String[] vStrs = vStr[i].split(",");
            int[] v = new int[vStrs.length];
            for (int i1 = 0; i1 < vStrs.length; i1++) {
                v[i1] = Integer.parseInt(vStrs[i1]);
            }
            int valueMax = getMaxValueByInts(v);
            valueSum = valueSum + valueMax;
        }

        System.out.println(valueSum);

    }

    private static int getMaxValueByInts(int[] v) {
        int valueMax = 0;

        int valueI = getValueByInts(v);
        valueMax = valueI;

        for (int i = 0; i < v.length; i++) {
            int[] vNew = move(v);
            valueI = getValueByInts(vNew);
            if (valueI > valueMax) {
                valueMax = valueI;
            }
        }

        return valueMax;
    }

    private static int[] move(int[] v) {
        int m = v[0];
        for (int i = 1; i <= v.length - 1; i++) {
            v[i - 1] = v[i];
        }
        v[v.length - 1] = m;
        return v;
    }

    private static int getValueByInts(int[] v) {
        String value = "";
        for (int i = 0; i < v.length; i++) {
            value = value + v[i];
        }
        int valueI = Integer.parseInt(value, 2);
        return valueI;
    }
}
